home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_server_info.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  8.8 KB  |  427 lines

  1. unit ntc_server_info;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     ExtCtrls,
  37.     inifiles,
  38.     Buttons,
  39.  
  40.     ntc_server_form,
  41.     ntc_server_network,
  42.     ntc_server_control,
  43.     ntc_server_object;
  44.  
  45. const
  46.     default_refresh_rate=30000;
  47.  
  48. type
  49.     Tscope_info = class(tform)
  50.         info_panel: TPanel;
  51.         coord_box: TGroupBox;
  52.         ra_label: TLabel;
  53.         alt_label: TLabel;
  54.         dec_label: TLabel;
  55.         az_label: TLabel;
  56.         hours_label: TLabel;
  57.         ra_minutes_label: TLabel;
  58.         ra_seconds_label: TLabel;
  59.         degrees_label: TLabel;
  60.         minutes_label: TLabel;
  61.         seconds_label: TLabel;
  62.         refresh_rate_label: TLabel;
  63.         dec_degrees_edit: TEdit;
  64.         alt_degrees_edit: TEdit;
  65.         az_degrees_edit: TEdit;
  66.         ra_hours_edit: TEdit;
  67.         ra_minutes_edit: TEdit;
  68.         ra_seconds_edit: TEdit;
  69.         dec_minutes_edit: TEdit;
  70.         dec_seconds_edit: TEdit;
  71.         az_minutes_edit: TEdit;
  72.         az_seconds_edit: TEdit;
  73.         alt_minutes_edit: TEdit;
  74.         alt_seconds_edit: TEdit;
  75.         refresh_rate_edit: TEdit;
  76.         msecs_label: TLabel;
  77.         info_label: TLabel;
  78.         get_ra_dec_button: TBitBtn;
  79.         get_alt_az_button: TBitBtn;
  80.         get_all_button: TBitBtn;
  81.     controller_timer: TTimer;
  82.     timer_button: TBitBtn;
  83.  
  84.         { form functions }
  85.         procedure formcreate(
  86.             Sender:TObject);
  87.  
  88.         procedure form_close_query(
  89.                     Sender: TObject;
  90.             var CanClose: Boolean);
  91.  
  92.         { information retrieval }
  93.         procedure get_info;
  94.  
  95.         Procedure show_info;
  96.  
  97.         procedure get_ra_dec;
  98.  
  99.         procedure get_az_alt;
  100.  
  101.         { configuration }
  102.         procedure load_settings;
  103.  
  104.         procedure save_settings;
  105.  
  106.         { events }
  107.         procedure FormShow(
  108.             Sender: TObject);
  109.  
  110.         procedure adjust;
  111.  
  112.         procedure check_activate(
  113.             Sender: TObject);
  114.  
  115.         procedure refresh_rate_editChange(
  116.             Sender: TObject);
  117.  
  118.         procedure get_ra_dec_buttonClick(
  119.             Sender: TObject);
  120.  
  121.         procedure get_alt_az_buttonClick(
  122.             Sender: TObject);
  123.  
  124.         procedure get_all_buttonClick(
  125.             Sender: TObject);
  126.  
  127.         procedure timer_buttonClick(
  128.             Sender: TObject);
  129.  
  130.         procedure controller_timerTimer(
  131.             Sender: TObject);
  132.  
  133.     private
  134.         { global information }
  135.     public
  136.         { Public declarations }
  137.         info_string:string;
  138.         { configuration }
  139.         dimensions:dimensions_record;
  140.         refresh_rate:integer;
  141.  
  142.         { events }
  143.         procedure check_visible_and_show_hide(
  144.             sender:tobject);
  145.             
  146.         procedure hide_form;
  147.         procedure show_form;
  148.     end;
  149.  
  150. var
  151.     scope_info: Tscope_info;
  152.  
  153. implementation
  154.  
  155. uses
  156.     ntc_server_focus,
  157.     ntc_server_comms,
  158.     ntc_server_config,
  159.     ntc_server_tracking,
  160.     ntc_server_search;
  161.  
  162. {$R *.dfm}
  163.  
  164.     { --------------
  165.         form functions
  166.         -------------- }
  167.  
  168. procedure Tscope_info.formcreate(
  169.     Sender:TObject);
  170. begin
  171.     controller_timer.Enabled:=false;
  172.     load_settings;
  173. end;
  174.  
  175. procedure Tscope_info.form_close_query(
  176.             Sender: TObject;
  177.     var CanClose: Boolean);
  178. begin
  179.     canclose:=false;
  180.     visible:=false;
  181.     with dimensions do
  182.         begin
  183.             form_top:=top;
  184.             form_left:=left;
  185.         end;
  186. end;
  187.  
  188.     { ---------------------
  189.         information retrieval
  190.         --------------------- }
  191.  
  192. Procedure tscope_info.show_info;
  193. var
  194.     h:hms;
  195.     d:dms;
  196.     a:ams;
  197. begin
  198.     with current_object do
  199.         begin
  200.             right_ascension_str(h);
  201.             with h do
  202.                 begin
  203.                     ra_hours_edit.text:=inttostr(hours);
  204.                     ra_minutes_edit.text:=inttostr(minutes);
  205.                     ra_seconds_edit.text:=inttostr(seconds);
  206.                 end;
  207.             declination_str(d);
  208.             with d do
  209.                 begin
  210.                     dec_degrees_edit.text:=inttostr(degrees);
  211.                     dec_minutes_edit.text:=inttostr(minutes);
  212.                     dec_seconds_edit.text:=inttostr(seconds);
  213.                 end;
  214.             azimuth_str(d);
  215.             with d do
  216.                 begin
  217.                     az_degrees_edit.text:=inttostr(degrees);
  218.                     az_minutes_edit.text:=inttostr(minutes);
  219.                     az_seconds_edit.text:=inttostr(seconds);
  220.                 end;
  221.             altitude_str(a);
  222.             with a do
  223.                 begin
  224.                     alt_degrees_edit.text:=inttostr(degrees);
  225.                     if (degrees<0) or (degrees>90) then
  226.                         begin
  227.                             scope_control.stop_scope;
  228.                             alt_degrees_edit.Color:=clRed
  229.                         end
  230.                     else
  231.                         alt_degrees_edit.Color:=clWindow;
  232.                     alt_minutes_edit.text:=inttostr(minutes);
  233.                     alt_seconds_edit.text:=inttostr(seconds);
  234.                 end;
  235.         end;
  236.     with info_label do
  237.         begin
  238.             caption:=info_string;
  239.             width:=240;
  240.         end;
  241. end;
  242.  
  243. procedure tscope_info.get_info;
  244. var
  245.     s:string;
  246. begin
  247.     with scope_network,scope_control,scope_focus,scope_tracking do
  248.          if (send_message_check('get_info')=[exit_ok]) and
  249.                 get_string('name',s) and
  250.                 get_boolean('can_goto',can_goto) and
  251.                 get_boolean('can_sync',can_sync) and
  252.                 get_boolean('can_slew',can_slew) and
  253.                 get_boolean('can_focus',can_focus) and
  254.                 ((can_focus and get_integer('focus_speeds',focus_speeds)) or
  255.                  not can_focus) and
  256.                 get_boolean('can_track',can_track) then
  257.         begin
  258.             name:=shortstring(s);
  259.             scope_name:=name;
  260.         end
  261.     else
  262.         begin
  263.             name:='';
  264.             scope_name:='unknown scope';
  265.         end;
  266. end;
  267.  
  268. procedure tscope_info.get_ra_dec;
  269. begin
  270.     with scope_network,scope_control,scope_focus,current_object do
  271.          if (send_message_check('get_ra_dec')=[exit_ok]) and
  272.                  get_float('ra',ra) then
  273.         get_float('dec',dec);
  274. end;
  275.  
  276. procedure tscope_info.get_az_alt;
  277. begin
  278.     with scope_network,scope_control,scope_focus,current_object do
  279.          if (send_message_check('get_az_alt')=[exit_ok]) and
  280.                  get_float('alt',alt) then
  281.         get_float('az',az);
  282. end;
  283.  
  284.     { -------------
  285.         configuration
  286.         ------------- }
  287.  
  288. procedure tscope_info.load_settings;
  289. begin
  290.     ini_file:=tinifile.create(application_path+'server.ini');
  291.     with ini_file do
  292.         begin
  293.             refresh_rate:=readinteger('info','refresh_rate',default_refresh_rate);
  294.             { form }
  295.             scope.get_dimensions(scope_info,@dimensions,'info',ini_file);
  296.             left:=dimensions.form_left;
  297.             top:=dimensions.form_top;
  298.             visible:=readbool('info','visible',false);
  299.         end;
  300.     ini_file.free;
  301. end;
  302.  
  303. procedure tscope_info.save_settings;
  304. begin
  305.     ini_file.writeinteger('info','refresh_rate',refresh_rate);
  306.     { form }
  307.     scope.find_vdu(scope_info,@dimensions);
  308.     scope.write_dimensions(@dimensions,left,top,'info',ini_file);
  309.     ini_file.writebool('info','visible',visible);
  310. end;
  311.  
  312.     { ------
  313.         events
  314.         ------ }
  315.  
  316. procedure Tscope_info.FormShow(
  317.     Sender: TObject);
  318. begin
  319.     with dimensions do
  320.         begin
  321.             top:=form_top;
  322.             left:=form_left;
  323.         end;
  324. end;
  325.  
  326. procedure tscope_info.adjust;
  327. begin
  328.     with dimensions do
  329.         begin
  330.             form_top:=trunc(form_top/last_screen_height*current_height);
  331.             form_left:=trunc(form_left/last_screen_width*current_width);
  332.         end;
  333.     if visible then
  334.         show;
  335. end;
  336.  
  337. procedure tscope_info.check_visible_and_show_hide(
  338.     sender:tobject);
  339. begin
  340.     if visible then
  341.         hide_form
  342.     else
  343.         show_form;
  344.     scope.show_hide(sender,visible);
  345. end;
  346.  
  347. procedure tscope_info.hide_form;
  348. begin
  349.     with dimensions do
  350.         begin
  351.             form_top:=top;
  352.             form_left:=left;
  353.         end;
  354.     Visible:=false;
  355. end;
  356.  
  357. procedure tscope_info.show_form;
  358. begin
  359.     Visible:=true;
  360. end;
  361.  
  362. procedure Tscope_info.check_activate(
  363.     Sender: TObject);
  364. begin
  365.     scope.form_activate(scope_info,@dimensions);
  366. end;
  367.  
  368. procedure Tscope_info.refresh_rate_editChange(
  369.     Sender: TObject);
  370. begin
  371.     refresh_rate:=strtointdef(refresh_rate_edit.text,0);
  372.     if refresh_rate<5000 then
  373.         begin
  374.             refresh_rate:=5000;
  375.             refresh_rate_edit.text:=inttostr(refresh_rate);
  376.         end;
  377. end;
  378.  
  379. procedure Tscope_info.get_ra_dec_buttonClick(
  380.     Sender: TObject);
  381. begin
  382.     get_ra_dec;
  383.     show_info;
  384. end;
  385.  
  386. procedure Tscope_info.get_alt_az_buttonClick(
  387.     Sender: TObject);
  388. begin
  389.     get_az_alt;
  390.     show_info;
  391. end;
  392.  
  393. procedure Tscope_info.get_all_buttonClick(
  394.     Sender: TObject);
  395. begin
  396.     get_ra_dec;
  397.     get_az_alt;
  398.     show_info;
  399. end;
  400.  
  401. procedure Tscope_info.timer_buttonClick(
  402.     Sender: TObject);
  403. begin
  404.     if controller_timer.enabled then
  405.         begin
  406.             controller_timer.Enabled:=false;
  407.             timer_button.caption:='Start';
  408.         end
  409.     else
  410.         begin
  411.             timer_button.caption:='Stop';
  412.             controller_timer.enabled:=true;
  413.         end;
  414. end;
  415.  
  416. procedure Tscope_info.controller_timerTimer(
  417.     Sender: TObject);
  418. begin
  419.     if not scope_comms.response_timer.enabled and scope_config.scope_enabled then
  420.         begin
  421.             get_info;
  422.             show_info;
  423.         end;
  424. end;
  425.  
  426. end.
  427.